package com.javaAPI.demo4;

import java.util.Scanner;

public class Login {
    public static void main(String[] args) {
        //1.正确用户名称和密码
//        String userName = "admin";
//        String passWord = "123456";
        //2.用户输入用户名称和密码
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入用户名称:");
        String user = scanner.nextLine();
        System.out.println("请输入用户密码:");
        String pwd = scanner.nextLine();

        //若用户输入为null，会报错
//        if (user.equals(userName) && pwd.equals(passWord)) {}

//        if (userName.equals(user) && passWord.equals(pwd)) {
//            System.out.println("登录成功");
//        } else {
//            System.out.println("账户或密码错误");
//        }

//        login1(user,pwd);

        System.out.println(login2(user, pwd) ? "登录成功":"账户或密码错误");

    }

    public static void login1(String user, String pwd) {
        String userName = "admin";
        String passWord = "123456";
        if (userName.equals(user) && passWord.equals(pwd)) {
            System.out.println("登录成功");
        } else {
            System.out.println("账户或密码错误");
        }
    }

    public static boolean login2(String user, String pwd) {
        String userName = "admin";
        String passWord = "123456";
        if (userName.equals(user) && passWord.equals(pwd)) {
            return  true;
        } else {
            return false;
        }
    }



}
